﻿using System.Collections.Generic;
using UnityEngine;

namespace Zhongy
{
    public class AccountCache
    {
        private Dictionary<string, ClientPer> dicAcc2ClientPer = new Dictionary<string, ClientPer>();
        private Dictionary<ClientPer, string> dicClientPer2Acc = new Dictionary<ClientPer, string>();

        public bool IsOnline(string ip)
        {
            return dicAcc2ClientPer.ContainsKey(ip);
        }

        public bool IsOnline(ClientPer clientPer)
        {
            return dicClientPer2Acc.ContainsKey(clientPer);
        }

        public void Online(ClientPer client, string account)
        {
            dicAcc2ClientPer.Add(account, client);
            dicClientPer2Acc.Add(client, account);
        }

        public void Offline(ClientPer client)
        {
            string account = dicClientPer2Acc[client];
            dicClientPer2Acc.Remove(client);
            dicAcc2ClientPer.Remove(account);

            Debug.Log(string.Format("存入当前对象{0}", account));
        }

        public void Offline(string account)
        {
            ClientPer client = dicAcc2ClientPer[account];
            dicAcc2ClientPer.Remove(account);
            dicClientPer2Acc.Remove(client);

            Debug.Log(string.Format("取消当前对象{0}", account));

        }
    }

}
